import Bullet, { BulletContact } from "./bullet";

const { disallowMultiple, ccclass, property } = cc._decorator;

@ccclass
@disallowMultiple
export default class BulletArea extends Bullet {
    @property({ override: true, visible: false })
    isSensor = true;
    @property({ override: true, visible: false })
    isGrabable = false;
    @property({ override: true, visible: false })
    isUseable = false;
    @property({ override: true, visible: false })
    isDynamic = false;
    @property({ override: true, visible: false })
    speed = cc.v2();
    @property({ override: true, visible: false })
    speedMax = cc.v2();

    bulletInArea: Bullet[] = [];
    onCollisionEnter(contact: BulletContact): void {
        if (contact.other) {
            this.bulletInArea.push(contact.other);
            this.onBulletEnterArea(contact.other);
        }
    }
    onCollisionExit(contact: BulletContact): void {
        if (contact.other) {
            let ind = this.bulletInArea.findIndex(ele => ele == contact.other);
            if (ind !== -1) {
                this.onBulletExitArea(this.bulletInArea.splice(ind, 1)[0]);
            }
        }
    }
    onBulletEnterArea(other: Bullet) { }
    onBulletExitArea(other: Bullet) { }
};